
import {EventEmitter} from 'fbemitter';
import AppDispatcher from './AppDispatcher';
import banckConstants from './constants';
const CHANGE_EVENT ='change';
let __emitter = new EventEmitter;
let balance =0;
let BankStore={

    getState(){
        return balance;
    },
    addListener:(callback)=>{
        return __emitter.addListener(CHANGE_EVENT,callback);
    },
};

BankStore.dispatchToken=AppDispatcher.register((action)=>{
    switch (action.type){
        case banckConstants.CREATED_ACCOUNT:
            balance=0;
            __emitter.emit(CHANGE_EVENT);
            break;
        case banckConstants.DEPOSITED_ACCOUNT:
            balance=balance+action.ammount;
            __emitter.emit(CHANGE_EVENT);
            break;
        case banckConstants.WITHDREW_FROM_ACCOUNT:
            balance=balance-action.ammount;
            __emitter.emit(CHANGE_EVENT);
            break;
    }
});

export default BankStore;